﻿@using System.Web.UI.WebControls
@using Dogshow.Model
@using DevExpress.Web.Mvc.UI
@model Mesto

@{
    ViewBag.Title = "Dogshow - Mesta";
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();
}

<script>
    function onFocusedRowChanged(s, e) {
        s.GetRowValues(s.GetFocusedRowIndex(), "Id;PostanskiBroj;Naziv", onGetRowValues);
        resetValidation();
    }

    function onGetRowValues(values) {
        $("#Id").val(values[0]);
        PostanskiBroj.SetText(values[1]);
        Naziv.SetText(values[2]);
        PostanskiBroj.Focus();
    }

    function onNoviUnos() {
        resetValidation();
        $("#Id").val(0);
        PostanskiBroj.SetText("");
        Naziv.SetText("");
        PostanskiBroj.Focus();
    }

    function resetValidation() {
        PostanskiBroj.SetIsValid(true);
        Naziv.SetIsValid(true);
    }

</script>

<div style="float: left; width: 300px;">
    @Html.Partial("MestaGridView")
</div>
<div style="margin-left: 355px;">
    <div class="line">
        @Html.DevExpress().HyperLink(
            s =>
            {
                s.Name = "lnkNov";
                s.Properties.Text = "Novi unos";
                s.Properties.ClientSideEvents.Click = "onNoviUnos";
                s.ControlStyle.Cursor = "pointer";
            }).GetHtml()
    </div>
     
    @using (Html.BeginForm("AzuirajMesto", "Mesta", FormMethod.Post, new {@class = "edit_form"}))
    {
        @Html.Hidden("Id", "0", new{id="Id"})
        <div class="line">
            @Html.DevExpress().Label(
                    s =>
                    {
                        s.ControlStyle.CssClass = "label";
                        s.Text = "Poštanski broj:";
                        s.AssociatedControlName = "PostanskiBroj";
                    }
                ).GetHtml()
            @Html.DevExpress().TextBox(
                    s =>
                    {
                        s.Name = "PostanskiBroj";
                        s.ControlStyle.CssClass = "editor";
                        s.Properties.ConvertEmptyStringToNull = true;
                        s.ShowModelErrors = true;
                    }).Bind(Model.PostanskiBroj).GetHtml()
        </div>
        <div class="line">
            @Html.DevExpress().Label(
                    s =>
                    {
                        s.ControlStyle.CssClass = "label";
                        s.Text = "Naziv mesta:";
                        s.AssociatedControlName = "Naziv";
                    }
                ).GetHtml()
            @Html.DevExpress().TextBox(
                    s =>
                    {
                        s.Name = "Naziv";
                        s.ControlStyle.CssClass = "editor";
                        s.Properties.ConvertEmptyStringToNull = true;
                        s.ShowModelErrors = true;
                    }).Bind(Model.Naziv).GetHtml()
        </div>
        <div class="line">
            @Html.DevExpress().Button(
                s =>
                {
                    s.Name = "btnSave";
                    s.Text = "Sačuvaj";
                    s.UseSubmitBehavior = true;
                    s.ControlStyle.CssClass = "btnSave";
                }
            ).GetHtml()
        </div>
    }
</div>




